package com.util;

import java.io.UnsupportedEncodingException;

import org.apache.http.entity.StringEntity;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.sys.Constants;
import com.sys.DemoApp;

public class MgqRestClient {
	public final static String TAG = "MgqRestClient";

	private static AsyncHttpClient client = new AsyncHttpClient();

	public static void get(String mothed, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		if (params != null) {
		}

		params.put("sec",Utils.Md5(mothed + "ylbb"));
		String url = Constants.SERVICE + mothed;
		client.setTimeout(120000);
		client.get(getAbsoluteUrl(url), params, responseHandler);
	}

	public static void post(String mothed, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		if (params != null) {
		}

		params.put("sec",Utils.Md5(mothed + "ylbb"));
		String url = Constants.SERVICE + mothed;
		client.setTimeout(120000);
		client.post(getAbsoluteUrl(url), params, responseHandler);
	}
	
	public static void postBody(String url, String params,
			AsyncHttpResponseHandler responseHandler) {
		if (params != null) {
		}
		
		client.setTimeout(120000);
		try {
			client.post(DemoApp.getContext(), getAbsoluteUrl(url), new StringEntity(params,"utf-8"), 
					"text/html;charset=utf-8", responseHandler);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	private static String getAbsoluteUrl(String relativeUrl) {
		return relativeUrl;
	}
}
